﻿using System.Collections.Generic;
using Model.DBInteractions;
using Model.EntityRepositories;
using Model.Entities;
using Model.Interfaces;

namespace Model.Services
{
    public class PageDetailService : IPageDetailService
    {
        private readonly IPageDetailRepository _PageDetailRepository;
        private readonly IUnitOfWork _unitOfWork;
        public PageDetailService(IPageDetailRepository PageDetailRepository, IUnitOfWork unitOfWork)
        {
            this._PageDetailRepository = PageDetailRepository;
            this._unitOfWork = unitOfWork;
        }  
        #region IPageDetailService Members

        public IEnumerable<PageDetail> GetPageDetails()
        {
            var PageDetails = _PageDetailRepository.GetAll();
            return PageDetails;
        }

        public PageDetail GetPageDetailById(int id)
        {
            var PageDetail = _PageDetailRepository.GetById(id);
            return PageDetail;
        }

        public void CreatePageDetail(PageDetail PageDetail)
        {
            _PageDetailRepository.Add(PageDetail);
            _unitOfWork.Commit();
        }

        public void DeletePageDetail(int id)
        {
            var PageDetail = _PageDetailRepository.GetById(id);
            _PageDetailRepository.Delete(PageDetail);
            _unitOfWork.Commit();
        }

        public void UpdatePageDetail(PageDetail PageDetail)
        {
            _PageDetailRepository.Update(PageDetail);
            _unitOfWork.Commit();
        }

        public void SavePageDetail()
        {
            _unitOfWork.Commit();
        }

        #endregion
    }
}
